package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.zhaoshang.ZsProject;
import com.yanqu.road.entity.zhaoshang.enums.eProjectStateType;
import com.yanqu.road.logic.pb.ZhaoShangPb;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.zhaoshang.ZsMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = CrossProtocol.C2_ZHAO_SHANG_MY_PROJECT_SEARCH, desc = "查询玩家立项的项目")
public class ZsMyProjectListCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        List<ZsProject> list = ZsMgr.getUserOpenProject(serverId, packet.getPlayerId(), eProjectStateType.InProgress.getIntValue());
        //转换Message
        ZhaoShangProto.ZsProjectListRespMsg.Builder respMsg = ZhaoShangProto.ZsProjectListRespMsg.newBuilder();
        respMsg.setRet(0);
        respMsg.setSearchUserAliasId(0);
        for(ZsProject entity : list){
            ZhaoShangProto.ZsProjectInfoTemp.Builder temp = ZhaoShangPb.parseZsProjectInfoTemp(entity, false, packet.getPlayerId());
            temp.setStateVal(ZsMgr.calZsProjectStateVal(entity));
            temp.setCross(ZsMgr.inGroup(entity.getServerId()));
            respMsg.addProjectList(temp);
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_ZS_MY_PROJECT_LIST, respMsg));
    }

    @Override
    public void sendData() {

    }
}
